
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>易买网 - 首页</title>
    <link type="text/css" rel="stylesheet" href="css/style.css" />
    <link type="text/css" rel="stylesheet" href="css/jquery.pagination.css"/>
    <script type="text/javascript" src="scripts/function.js"></script>
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="js/jquery.pagination.min.js"></script>
    <style>
        .box {
            width: 500px;
            margin: 0px auto 0;
            height: 34px;
        }

        .page {
            width: 700px;
        }

        .fl {
            float: left;
        }
    </style>
 </head>
<body>
<div id="header" class="wrap">
    <div id="logo"><img src="images/logo.gif" /></div>
    <div class="help"><a href="#" class="shopping">购物车</a><a href="login.html">登录</a><a href="register.html">注册</a><a href="guestbook.html">留言</a></div>
</div>
<div id="childNav">
    <div class="wrap">
        <ul class="clearfix">
            <li class="first"><a href="index.jsp">首页</a></li>
            <li><a href="#">影视</a></li>
            <li><a href="#">少儿</a></li>
            <li><a href="#">动漫</a></li>
            <li><a href="#">小说</a></li>
            <li><a href="#">外语</a></li>
            <li><a href="#">数码相机</a></li>
            <li><a href="#">笔记本</a></li>
            <li><a href="#">羽绒服</a></li>
            <li><a href="#">秋冬靴</a></li>
            <li><a href="#">运动鞋</a></li>
            <li><a href="#">美容护肤</a></li>
            <li><a href="#">家纺用品</a></li>
            <li><a href="#">婴幼奶粉</a></li>
        </ul>
    </div>
</div>
<div id="position" class="wrap">
    您现在的位置：<a href="index.html">易买网</a> &gt; 在线留言
</div>
<%----%>
<div id="main" class="wrap">
    <div class="lefter">
        <%@include file="logo.jsp"%>
        <div class="spacer"></div>
        <div class="last-view" style="margin-left: -100px;width: 200px;">
            <h2>最近浏览</h2>
            <dl class="clearfix">
                <dt><img src="images/product/0_tiny.gif"/></dt>
                <dd><a href="product-view.html">法国德菲丝松露 精品巧克力500g/盒</a></dd>
                <dt><img src="images/product/0_tiny.gif"/></dt>
                <dd><a href="product-view.html">法国德菲丝松露 精品巧克力500g/盒</a></dd>
            </dl>
        </div>
    </div>
    <div class="main">
        <div class="guestbook">
            <h2>全部留言</h2>
            <ul id="replyul"></ul>
            <div class="clear"></div>

            <div class="box">
                <div id="pagination2" class="page fl"></div>
            </div>

            <div id="reply-box">
                <form method="post" action="AddTopicServlet">
                    <table>
                        <tr>
                            <td class="field">昵称：</td>
                            <td><input class="text" type="text" name="name" id="keyword"/><span id="myspan"></span></td>
                        </tr>
                        <tr>
                            <td class="field">留言标题：</td>
                            <td><input class="text" type="text" name="title" /></td>
                        </tr>
                        <tr>
                            <td class="field">留言内容：</td>
                            <td><textarea name="context"></textarea></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td><label class="ui-blue"><input type="submit" name="submit" value="提交留言" /></label></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
    <div class="clear"></div>
</div>
<div id="footer">
    Copyright &copy; 2018 项目一组 All Rights Reserved. 京ICP证1000001号
</div>
</body>
</html>
<script type="text/javascript">
    $(function () {
        var pageNo;
        var totalPages;
        var $getReply=function (curr) {
            $.ajax({
                type:"POST",
                url:"GetALLReplyServlet",
                data:{
                    pageNo:curr||1
                },
                dataType:"JSON",
                success:function (data) {
                    pageNo=data.pageNo;
                    totalPages=data.totalPage;
                    $("#replyul").find("li").remove();
                    $.each(data.items,function (index,obj) {
                        var newLiList=" <li><dl><dt>"+obj.topic.title+"</dt><dd class=\"author\">网友："+obj.topic.user.name+"<span class=\"timer\">"+obj.ptime+"</span></dd><dd>"+obj.context+"</dd></dl></li>";
                        $("#replyul").append(newLiList);
                    })

                    $("#pagination2").pagination({
                        currentPage: curr,
                        totalPage: totalPages,
                        isShow: true,
                        count: 5,
                        prevPageText: "< 上一页",
                        nextPageText: "下一页 >",
                        callback: function(current) {
                            $("#current2").text(current)
                            $getReply(current);
                        }
                    });
                }

            })
        }
        $getReply();



        /*$(".pages").on("click",function () {
            var pageid=$(this).attr("id");
            if(pageid=="prevpage"){
                pageNo--;
                $getReply(pageNo);

            }
            if(pageid=="nextpage"){
                pageNo++;
                if(pageNo>totalPage){
                    pageNo=totalPage;
                }
                $getReply(pageNo);
            }
        });*/

    });
    $(function () {
        $("#keyword").blur(function () {
            $.ajax({
                type:"POST",
                url:"",
                data:{
                    keyword:$("keyword").val()
                },
                success:function (data) {
                    if(data=="true"){
                        $("#myspan").html("可以使用");
                    }
                    if(data=="false"){
                        $("#myspan").html("请先登录再留言");
                    }
                }
            });
        });
    });

</script>
